package Messages;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

import javax.swing.JOptionPane;

import ocsf.server.ConnectionToClient;

import server.SQLConnection;
/**
 * this class implements the workers view details of subscribers
 * @author Ron Shenkerman
 * @author Gabi Revah
 * @author Aviad Almog
 * @author Ivan Onyshchenko
 */
public class MessageViewSubscriberDetails {
	
	private String id,username,tel,email,status;
	private ConnectionToClient client ;
/**
 * constractor of this class 	
 * @param client
 */
public MessageViewSubscriberDetails(ConnectionToClient client) {
		super();
		this.client = client;
	}
/**
 * view subscriber details form the db 
 * @param idd
 */
public void viewdetail(String idd){
		
		try 
		{

			System.out.println("Getting subscriber detail for viewing");
			Statement stmt;
			SQLConnection conn = new  SQLConnection();
			stmt = conn.getConnection().createStatement();
			ResultSet rs= stmt.executeQuery("SELECT * FROM db1.subscriber WHERE id='"+idd+"';");
				try {
				
						if (rs.next())
							{
							 System.out.println("str====="+idd);	
								id=rs.getString(1);
								username=rs.getString(3);
								tel=rs.getString(4);
								email=rs.getString(2);
								status=rs.getString(5);
								System.out.println("id:"+id+"  username:"+username+"  tel:"+tel+"  email:"+email+"  status:"+status);
								
								ArrayList<String> ViewArr=new ArrayList<String>();
								ViewArr.add("ViewSubscriberDetails");
						        ViewArr.add(id);
						        ViewArr.add(username);
						        ViewArr.add(email);
						        ViewArr.add(tel);
						        
								client.sendToClient(ViewArr);
								
							}
						else 
							{
								
								client.sendToClient("subscriberdoesntexists");
							}
  
					}
						catch (SQLException e)
								{	
								e.printStackTrace();
								}
		}
  
		catch (Exception ex )
		{
	  ex.printStackTrace();
		}


}
	
	
	
	

}
